<template>
  <!-- 合同信息 -->
  <div id="contractDetail">
    <el-form :model="form" label-width="100">
      <el-form-item label="合同编号:" style="width: 100%">
        <p>{{ form.num }}</p>
      </el-form-item>
      <el-form-item label="合同名称:">
        <p>{{ form.name }}</p>
      </el-form-item>
      <el-form-item label="合同简称:">
        <p>{{ form.name }}</p>
      </el-form-item>
      <!-- <el-form-item label="客户名称:">
        <p>{{ form.customerName }}</p>
      </el-form-item> -->
      <el-form-item label="客户电话:">
        <p>{{ form.secondPhone }}</p>
      </el-form-item>
      <el-form-item label="合同类型:">
        <p>{{ form.typeName }}</p>
      </el-form-item>
      <el-form-item label="合同金额:">
        <p>{{ form.money ? form.money : 0 }}元</p>
      </el-form-item>
      <el-form-item label="签订时间:">
        <p>{{ form.orderTime }}</p>
      </el-form-item>
      <el-form-item label="条款:" style="width: 100%">
        <p class="title" @click="showClauseDetail">
          {{ form.lessorArticleTitle }}
        </p>
      </el-form-item>
      <el-form-item label="备注:" style="width: 100%">
        <p>{{ form.remark }}</p>
      </el-form-item>
      <el-form-item label="附件:" style="width: 100%">
        <!-- <p>{{ form.otherFiles }}</p> -->
        <other-files ref="otherFiles" :files="form.otherFiles"></other-files>
      </el-form-item>
      <el-form-item label="审批状态:" v-if="isReloadData">
        <!-- 0，待审核，1审核通过，2审核不通过 -->
        <p v-if="form.totalStatus == 0" style="color: #e6a23c">待审核</p>
        <p v-if="form.totalStatus == 1" style="color: #67c23a">通过</p>
        <p v-if="form.totalStatus == 2" style="color: #f56c6c">未通过</p>
        <p v-if="form.totalStatus == 3" style="color: #ff9b31">审核中</p>
      </el-form-item>
      <el-form-item label="创建人:">
        <p>{{ form.username }}</p>
      </el-form-item>
      <el-form-item label="创建时间:">
        <p>{{ form.createTime }}</p>
      </el-form-item>
    </el-form>
  </div>
  <clause-dialog ref="clauseDialog" @saveClauseDetail="saveClauseDetail">
  </clause-dialog>
</template>
<script>
import { queryTypeByDic } from '@/utils/getData'
import otherFiles from '@/components/otherFiles'
import clauseDialog from '../../components/clauseDialog.vue'
export default {
  name: 'contractDetail',
  data () {
    return {
      form: {},
      isReloadData: true,//局部刷新标识
      typeList: []//合同类型列表
    }
  },
  components: {
    otherFiles,
    clauseDialog
  },
  props: {
    data: {
      type: Object,
      required: true,
      default: () => { return {} }
    }
  },
  watch: {
    data (val) {
      if (val) {
        this.form = val
        this.typeList.forEach(item => {
          if (item.value == val.type) {
            this.form.typeName = item.name
          }
        })
      }
    }
  },
  mounted () {
    this.getContractType()
  },
  methods: {
    // 获取合同类型
    async getContractType () {
      let list = await queryTypeByDic('contractType')
      this.typeList = list
    },

    // 查看合同详情
    showClauseDetail () {
      let data = {
        articleTitle: this.form.lessorArticleTitle,
        articleText: this.form.lessorArticle
      }
      this.$refs.clauseDialog.open(data)
    },
    relodPart () {
      this.isReloadData = false
      this.$nextTick(() => {
        this.isReloadData = true
      })
    }
  }
}
</script>
<style lang='scss' scoped>
.title {
  // margin-top: 5px;
  color: #409eff;
  cursor: pointer;
  &:hover {
    text-decoration: underline;
  }
}
</style>